package com.yanqu.road.dao.impl.activity.stelesoul;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.stelesoul.config.SteleSoulReviewConfig;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class SteleSoulStoneSoulReviewConfigDaoImpl extends TempDao {
    private static String getSteleSoulStoneSoulReviewConfigSql = "select * from `t_s_activity_stonesoul_review` where `activityId`=?";

    public Map<Integer, SteleSoulReviewConfig> getSteleSoulReviewConfig(int activityId) {
        Map<Integer, SteleSoulReviewConfig> map = new ConcurrentHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getSteleSoulStoneSoulReviewConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                SteleSoulReviewConfig steleSoulReviewConfig = new SteleSoulReviewConfig();
                steleSoulReviewConfig.setActivityId(rs.getInt("activityId"));
                steleSoulReviewConfig.setAward(rs.getString("award"));
                steleSoulReviewConfig.setIsReview(rs.getInt("isReview"));
                steleSoulReviewConfig.setRewardList(rs.getString("rewardList"));
                steleSoulReviewConfig.setSelectReward(rs.getString("selectReward"));
                int layer = rs.getInt("layer");
                steleSoulReviewConfig.setLayer(layer);
                map.put(layer, steleSoulReviewConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }
}
